//思路：对头节点进行处理，在接着对后面进行处理后面处理的细节需要注意

class ListNode{
   int val;
   ListNode next;
   public ListNode(){};

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next){
       this.val=val;
       this.next=next;
   }
}
 public class Solution {

     public  ListNode removeElements(ListNode head, int val) {
         while(head!=null&&head.val==val){
             head=head.next;
         }
         if(head==null) return null;
         ListNode p=head;
         while(p.next!=null){
             if(p.next==null) break;
             ListNode s=p.next;
             if(s.val==val){
                 p.next=s.next;
             } else{
                 p=p.next;
             }

         }
         return head;
     }
        }







